using System;
using System.Collections.Generic;
using UnityEngine;


namespace BF
{
    public class UnityMonoEvent : MonoBehaviour
    {
        public static UnityMonoEvent instance { get; private set; }

        public static event Action onUpdate;
        public static event Action onFixedUpdate;
        public static event Action<bool> onApplicationPause;
        public static event Action<bool> onApplicationFocus;
        public static event Action onApplicationQuit;

        static UnityMonoEvent()
        {
            GameObject go = new GameObject("UnityMonoEvent");
            instance = go.AddComponent<UnityMonoEvent>();
            DontDestroyOnLoad(go);
        }

        private void Awake()
        {
            if (instance != null && instance != this)
            {
                Destroy(this.gameObject);
            }
        }

        private void Update()
        {
            onUpdate?.Invoke();
        }

        private void FixedUpdate()
        {
            onFixedUpdate?.Invoke();
        }

        private void OnApplicationPause(bool pause)
        {
            onApplicationPause?.Invoke(pause);
        }

        private void OnApplicationFocus(bool focus)
        {
            onApplicationFocus?.Invoke(focus);
        }

        private void OnApplicationQuit()
        {
            onApplicationQuit?.Invoke();
        }
    }
}
